package legoproject.Behaviors;

import legoproject.*;
import lejos.nxt.*;
import java.util.ArrayList;

public class AvoidEdge implements Behavior {

    private boolean left = true;
    private boolean right = true;

    public boolean condition() {
        left = GarbageCollector.leftTouchSensor.isPressed();
        right = GarbageCollector.rightTouchSensor.isPressed();
        return (!right || !left);
    }

    public ArrayList behave() {

        ArrayList result = new ArrayList();
        result.add(new Instruction(InstructionType.DRIVE, -800, 50));
        if (!left) {
            result.add(new Instruction(InstructionType.ROTATE, -90, 0));

        } else if (!right) {
            result.add(new Instruction(InstructionType.ROTATE, 90, 0));
        }
        return result;
    }
}